/*
 * Copyright 2008-2023 dexian.vip. All rights reserved.
 * Support: http://www.dexian.vip
 * License: http://www.dexian.vip/license
 */

package vip.dexian.common.query;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.math.BigDecimal;

/**
 * 数值 BigDecimal between
 *
 * @author 挺好的 2023年05月30日 18:44
 */
@Data
@EqualsAndHashCode (callSuper = false)
@SuperBuilder
@NoArgsConstructor
public class DecimalBetween extends BaseBetween <BigDecimal, BigDecimal> {

    /**
     * 创建时间数值范围的查询条件
     *
     * @param lowerBound
     *         左边的值
     * @param upperBound
     *         右边的值
     *
     * @return
     */
    public static DecimalBetween of (BigDecimal lowerBound, BigDecimal upperBound) {
        return DecimalBetween.builder().lowerBound(lowerBound).upperBound(upperBound).build();
    }


    /**
     * 是否有效，如果无效，将不添加到搜索条件中。
     * 当 lowerBound == null || upperBound == null ，返回false， 仅当 lowerBound < upperBound ，返回true;
     *
     * @return 是否有效
     */
    @Override
    public boolean isValid () {
        BigDecimal lowerBound = super.getLowerBound();
        BigDecimal upperBound = super.getUpperBound();

        if (lowerBound == null || upperBound == null) {
            return false;
        }

        return upperBound.compareTo(lowerBound) > 0;
    }

    @Override
    public String toString () {
        return super.toString();
    }
}
